package com.vision.world.survey.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.vision.world.survey.R;
import com.vision.world.survey.managers.QueryManager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Ada on 2017/10/11.
 */
public class SearchResultAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private List<Map<String,Object>> items=new ArrayList<>();

    public SearchResultAdapter(Context context){
        this.mInflater = LayoutInflater.from(context);
    }
    public void setItem(List<Map<String,Object>> list){
        items= list;//QueryManager.getInstance().SearchResultFromOperationLayer;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Map<String,Object> getItem(int i) {
        return items.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_lv_search_result, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        ViewHolder holder = (ViewHolder) convertView.getTag();
        Map<String,Object> item=getItem(position);
//        int index=position+1;
//        holder.id.setText(""+index);
        holder.name.setText(item.get("NAME").toString());
        return convertView;
    }

    static class ViewHolder {
//        final TextView id;
        final TextView name;
        ViewHolder(View view) {
//            id = (TextView) view.findViewById(R.id.txt_search_result_index);
            name = (TextView) view.findViewById(R.id.txt_search_result_name);
        }
    }
}
